#pragma once
#include <Vector2.h>
#include <SDL/SDL.h>
#include <Image.h>
#include <so_math.h>
#include <Timer.hpp>
#include <CollisionEntity.h>
#include <Part.h>
#include <IRotation.h>
#include <IMotion.h>
#include <IVisible.h>
#include <IGameObject.h>
#include <ICollision.h>
#include <IAnimation.h>
class SpaceScene;
class EntityManagement;
enum class Flip{
    NONE,HORIZONTAL,VERTICAL
};
struct Slot
{
    Part* part = nullptr;
    Vector2 position;
    int layer;
    Flip flip;
};
enum class UnitOrderType
{
    STOP=0,
    MOVE=2,
    ATTACKMOVE=4,
    ATTACK=8,
    FOLLOW=16,
    HARVEST=32,
    WITHDRAW=64
};
class Entity : public IMotion,public IRotation, public IVisible, public IGameObject, public ICollision
{
    friend EntityManagement;
    friend SpaceScene;

public:
    enum class ImageDirect
    {
        UP,
        DOWN,
        LEFT,
        RIGHT
    };

protected:
    Entity();
    ~Entity();
    real allowMoveFacingDifference;
private:
    Slot slots[4];
    char name[0xff];
    Vector2 slotsPosition[4];

    bool selectable;
    int selectedRange;
    int selectedSize;
    bool isSelected = false;
    bool decelerating = false;
    bool accelerating = false;
    bool isBuilding = false;
    bool isResource = false;
    bool isBase = false;
    bool hover = false;
    Entity* harvestUnit = nullptr;
    int orderType = (int)UnitOrderType::STOP;

public:

    real rotate(real delta, real target_angle);
    bool move(real delta, Vector2 target);
    bool approach(real delta, Vector2 target, real min_distance);
    void update(real delta);
    void setSlot(Part* part,int slot);
    Slot* getSlots();
    Vector2 getSlotPosition(int index);
};